from crewai import Agent, Crew, Process, Task
from crewai.project import CrewBase, agent, crew, task

# If you want to run a snippet of code before or after the crew starts, 
# you can use the @before_kickoff and @after_kickoff decorators
# https://docs.crewai.com/concepts/crews#example-crew-class-with-decorators

@CrewBase
class ResearchCrew():
    """Research crew"""

    # Learn more about YAML configuration files here:
    # Agents: https://docs.crewai.com/concepts/agents#yaml-configuration-recommended
    # Tasks: https://docs.crewai.com/concepts/tasks#yaml-configuration-recommended
    agents_config = 'config/agents.yaml'
    tasks_config = 'config/tasks.yaml'

    # If you would like to add tools to your agents, you can learn more about it here:
    # https://docs.crewai.com/concepts/agents#agent-tools
    @agent
    def researcher(self) -> Agent:
        """Researcher agent"""
        return Agent(
          config=self.agents_config['researcher'], # pylint: disable=invalid-sequence-index
          verbose=True
        )

    @agent
    def reporting_analyst(self) -> Agent:
        """Reporting analyst agent"""
        return Agent(
          config=self.agents_config['reporting_analyst'], # pylint: disable=invalid-sequence-index
          verbose=True
        )

    # To learn more about structured task outputs,
    # task dependencies, and task callbacks, check out the documentation:
    # https://docs.crewai.com/concepts/tasks#overview-of-a-task
    @task
    def research_task(self) -> Task:
        """Research task"""
        return Task(
          config=self.tasks_config['research_task'], # pylint: disable=invalid-sequence-index
        )

    @task
    def reporting_task(self) -> Task:
        """Reporting task"""
        return Task(
          config=self.tasks_config['reporting_task'], # pylint: disable=invalid-sequence-index
          output_file='report.md'
        )

    @crew
    def crew(self) -> Crew:
        """Creates the LatestAiDevelopment crew"""
        # To learn how to add knowledge sources to your crew, check out the documentation:
        # https://docs.crewai.com/concepts/knowledge#what-is-knowledge

        return Crew(
          agents=self.agents, # pylint: disable=no-member
          tasks=self.tasks, # pylint: disable=no-member
          process=Process.sequential,
          verbose=True,
          chat_llm="gpt-4o"
          # process=Process.hierarchical, # In case you wanna use that instead https://docs.crewai.com/how-to/Hierarchical/
        )
